
#include <QtGui/QApplication>
#include <QTextCodec>
#include <QWSServer>
#include <QColor>
#include <QBrush>
#include <QDebug>
#include <QFile>
#include <QFileInfo>
#include <QTextStream>

#include "mainwindow.h"
#include "macro_def.h"

#ifndef DESK_TOP_RUN
//#define LOG_TXT
#ifdef  LOG_TXT
void customMessageHandler(QtMsgType type, const char *msg)
{
        QString txt;
        switch (type) {
        //调试信息提示
        case QtDebugMsg:
                txt = QString("Debug: %1").arg(msg);
                break;

        //一般的warning提示
        case QtWarningMsg:
                txt = QString("Warning: %1").arg(msg);
        break;
        //严重错误提示
        case QtCriticalMsg:
                txt = QString("Critical: %1").arg(msg);
        break;
        //致命错误提示
        case QtFatalMsg:
                txt = QString("Fatal: %1").arg(msg);
                abort();
        }

        QFileInfo info1(LOG_FILE);
        if(info1.size() > 64*1024){
            QFile::remove(LOG_FILE);
        }

        QFile outFile(LOG_FILE);
        outFile.open(QIODevice::WriteOnly | QIODevice::Append);
        QTextStream ts(&outFile);
        ts << txt << endl;
}
#endif
#endif

int main(int argc, char *argv[])
{

    /*
      当前几个不企鹅顶的问题：
       1.进入熔接或者是放电模式时，是否还允许进入设置界面
       2.熔接结果/放电测试结果出来之后的按键选择安排
    */
#ifndef DESK_TOP_RUN
    QWSServer::setBackground(QBrush(QColor(0,0,0,0)));
#ifdef  LOG_TXT
    //注册自己的MsgHandler
    qInstallMsgHandler(customMessageHandler);
#endif
#endif

    QApplication a(argc, argv);
    //QTextCodec::setCodecForTr(QTextCodec::codecForName("GB2312"));

    //加载语言配置文件,预加载中文--lbs 20170425
    QTranslator my_translator;
    my_translator.load(QString(":/language_zh"));
    a.installTranslator(&my_translator);

    MainWindow w;

    QTextCodec *codec = QTextCodec::codecForName("UTF-8");
    QTextCodec::setCodecForCStrings(codec);
    QTextCodec::setCodecForTr(codec);
    QTextCodec::setCodecForLocale(codec);
    QFont font;
    font.setPixelSize(16);
    font.setFamily(("WenQuanYi Zen Hei"));
    font.setBold(true);
    a.setFont(font);

    //--lbs 20170425
    w.setTranslator(&my_translator);
    w.show();
    w.setLanguage();  //必须先show完了 再设置语言，原理是  show是在初始化button 只有button完全出现，才可以设置子属性--语言

    return a.exec();
}
